package com.model;

/**
 * @author Erik
 * 2017-08-12
 */
public class Student {
    private String studentNo;
    private String studentName;
    private String studentSex;
    private Subject studentSubject;
    private int studentAge;

    //Getters
    public String getStudentNo()    {   return this.studentNo;  }
    public String getStudentName()  {   return this.studentName;}
    public String getStudentSex()   {   return this.studentSex; }
    public int getStudentAge()      {   return this.studentAge; }

    /**
     * 获取专业对象
     * @return 专业对象
     *
     * 如果对象不存在，则生成一个新的对象
     */
    public Subject getStudentSubject()
    {
        if(this.studentSubject==null)
            this.studentSubject=new Subject();
        return this.studentSubject;
    }

    //Setters
    public void setStudentNo(String studentNo)      {   this.studentNo = studentNo;     }
    public void setStudentName(String studentName)  {   this.studentName = studentName; }
    public void setStudentSex(String studentSex)
    {
        if(studentSex.equals("男")||studentSex.equals("女"))
            this.studentSex = studentSex;
        else
            this.studentSex="NULL";
    }

    public void setStudentAge(int studentAge)
    {
        if(studentAge>=100 || studentAge<=10)
            studentAge=0;
        this.studentAge = studentAge;
    }

    public void setStudentSubject(Subject studentSubject) {
        this.studentSubject = studentSubject;
    }

    //No-Argument constructor
    public Student(){}

    //Constructor with arguments
    public Student(String no,String name,String sex,int age){
        this.setStudentAge(age);
        this.setStudentName(name);
        this.setStudentNo(no);
        this.setStudentSex(sex);

    }

    public Student(String no,String name,String sex,int age,Subject studentSubject){
        this.setStudentAge(age);
        this.setStudentName(name);
        this.setStudentNo(no);
        this.setStudentSex(sex);
        this.setStudentSubject(studentSubject);

    }

    /**
     * 学生基本信息
     * @return 学号、姓名、性别、年龄
     */
    public String info(){
         String information="学号:     "+getStudentNo()
                 +"\n姓名:     "+getStudentName()
                 +"\n性别:     "+getStudentSex()
                 +"\n年龄:     "+getStudentAge()
                 +"\n专业编号:   "+this.getStudentSubject().getSubjectNo()
                 +"\n专业学制:   "+this.getStudentSubject().getSubjectLife();
          return information;
    }

    /**
     * 重载学生信息类，将学生信息和专业信息联系到一起
     * @param 专业类
     * @return 学生学号、姓名、性别、年龄，专业编号、学制年限
     */
    public String info(Subject mySub){
        String information="学号:     "    +getStudentNo()
                +"\n姓名:     "+getStudentName()
                +"\n性别:     "+getStudentSex()
                +"\n年龄:     "+getStudentAge()
                +"\n专业编号:   "+mySub.getSubjectNo()
                +"\n专业学制:   "+mySub.getSubjectLife();
        return information;
    }
}
